using System;
using System.Collections.Generic;

namespace BusinessLogic.Mappers
{
	abstract class EnumMapping<Enum, Key>
	{
		private static readonly IDictionary<Enum, Key> dtoMap = new Dictionary<Enum, Key>();
		private static readonly IDictionary<Key, Enum> enumMap = new Dictionary<Key, Enum>();

		protected static void AddMapping(Enum enumValue, Key key)
		{
			dtoMap[enumValue] = key;
			enumMap[key] = enumValue;
		}

		public Enum Map(Key key)
		{
			if(!enumMap.ContainsKey(key))
			{
				throw new ArgumentException(string.Format("There's no mappings for key '{0}' in {1}.", key, GetType()));
			}

			return enumMap[key];
		}

		public Key Map(Enum key)
		{
			if(!dtoMap.ContainsKey(key))
			{
				throw new ArgumentException(string.Format("There's no mappings for key '{0}' in {1}.", key, GetType()));
			}

			return dtoMap[key];
		}
	}
}